<?php
namespace app\controller;

use think\Controller;
use think\Exception;
use think\facade\Request;

class Artical extends Controller
{
    protected $beforeActionList = [
        'first',
    ];

    protected function first()
    {
       if($_SERVER['REQUEST_METHOD']=='OPTIONS'){
           return $_SERVER['REQUEST_METHOD'];
       }
    }

    protected function second()
    {
        echo 'second<br/>';
    }
    public function index()
    {
        $data=db('sar_article')->select();
        return json_encode($data);
    }


    public function save()
    {
        try{
            $postData=Request::post();
            $data=$postData['data'];
            $guid=md5(rand());
            $saveData=[
                'pk_article_guid'=>$guid,
                'fk_category_guid'=>'1',
                'title'=>$data['title'],
                'content'=>$data['content']
            ];
            $res=db('sar_article')->insert($saveData);
            return $guid;
        }catch (\Exception $e){
            return '未知错误';
        }

    }
}
